Repository navigation
[2.x] Improve multipleOf divisor messages and handle non-finite divisors - #1330
Conversation
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 2.x #1330 +/- ##
======================================
Coverage ? 79.25%
Complexity ? 2112
======================================
Files ? 202
Lines ? 7023
Branches ? 1272
======================================
Hits ? 5566
Misses ? 1003
Partials ? 454 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Thanks for the PR. Findings from review. Tests pass locally (162 on JDK 8). Points 1–4 are shared with #1329; 5–6 are specific to 2.x.
|
|
Thanks for the update. I re-reviewed d56a711. Fixed: point 3. Still open (the main code hasn't changed):
Please address these or reply on whether you plan to. If you disagree with any of them, a short note is fine. |
|
Thanks for the re-review. The remaining points are now addressed:
The literal, multi-digit boundary tests for point 3 remain in place. Javadoc and CHANGELOG now describe the final behavior. All 192 MultipleOfValidatorTest cases pass on JDK 8. |
|
Thanks for this. The formatting part matches #1329 and looks correct. I fuzzed the plain-length formula against Behavior1. Non-finite values now fail open, and the CHANGELOG should say so plainly With the default reader, 2. "Matching master" only holds for On master,
Code3. Reuse This keeps the two branches textually aligned for future cherry-picks: if (node.isNumber()) {
if (JsonNodeTypes.isNonFiniteNumber(node)) {
return null;
}
if (node.isIntegralNumber() || node.isBigDecimal()) {
return node.decimalValue();
}
return BigDecimal.valueOf(node.doubleValue());
}4. Avoid converting to a string twice in String text = value.toString();
if (length > text.length()) {
return text;
}
return text.indexOf('E') < 0 ? text : value.toPlainString();5. Update the It still says Double/Float nodes are converted with Tests6. ±10^400 is an exact multiple of 2, so the test passes either way. Using 7. Restore coverage for a Removing @ParameterizedTest
@ValueSource(doubles = {Double.NaN, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY})
void nonFiniteDivisorOverrideIsStillUsed(double value) {
Schema parent = SchemaRegistry.withDefaultDialect(SpecificationVersion.DRAFT_2020_12)
.getSchema("{\"multipleOf\":2}");
for (JsonNode schemaNode : new JsonNode[] {DoubleNode.valueOf(value), FloatNode.valueOf((float) value)}) {
MultipleOfValidator validator = new MultipleOfValidator(SchemaLocation.of("#/multipleOf"),
schemaNode, parent, parent.getSchemaContext()) {
@Override
protected BigDecimal getDivisor(JsonNode node) {
return BigDecimal.valueOf(2);
}
};
ExecutionContext context = parent.createExecutionContext();
JsonNode input = IntNode.valueOf(3);
validator.validate(context, input, input, new NodePath(PathType.JSON_POINTER));
assertEquals(1, context.getErrors().size());
}
}8. Merge Both override 9. Simplify The |
|
Thanks for the detailed follow-up. All nine points are now addressed:
All 194 MultipleOfValidatorTest cases pass on JDK 8 and 17, and the full suite passes on JDK 8. |
stevehu
left a comment
There was a problem hiding this comment.
Thanks, I re-reviewed 8e9b185 and all nine points are addressed:
- the CHANGELOG states the fail-open behavior and scopes parity to
multipleOf; getDividendreusesJsonNodeTypes.isNonFiniteNumber;- both Javadocs describe non-finite handling;
- the overflow test uses divisor 3;
getDivisoroverride coverage for non-finite schema nodes is restored;- the dividend-override tests are merged.
MultipleOfValidatorTest passes locally (194 tests on JDK 21) and CI is green on Java 8 through 21.
I'll follow up separately with one small docs tweak, so no changes needed here: the CHANGELOG note on USE_BIG_DECIMAL_FOR_FLOATS should say it needs to be enabled on the registry's NodeReader, since enabling it on an application mapper doesn't affect schema loading.
Approving and merging.
The CHANGELOG note for non-finite multipleOf values did not say where USE_BIG_DECIMAL_FOR_FLOATS must be enabled. Point to the SchemaRegistry's NodeReader, and to the caller's mapper for pre-parsed JsonNode instances. Follow-up to #1330. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Refs #1328. Corresponding master PR: #1329.
Display
multipleOfdivisors in plain notation when the result fits within 32 characters or is no longer thanBigDecimal.toString(). Check the length before expansion to avoid excessive padding for extreme scales. Apply this formatting to customgetDivisor()results while preserving trailing zeros.Ignore zero divisors returned by overrides, regardless of scale, matching the default conversion.
Align the default handling of non-finite divisors and dividends with master's
multipleOfbehavior. This is a fail-open change: values such as1e400that the default reader converts to infinity are now accepted by this constraint instead of causing an exception. A non-finite divisor disables the constraint for all instances; a non-finite dividend skips the check for that instance. EnableDeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATSto validate these decimal values exactly (see #1293). Exact integral and BigDecimal values remain validated, and customgetDividend()results are still used. Other numeric keywords on 2.x retain their existing behavior.Update Javadoc and CHANGELOG, and add regression coverage for formatting, zero divisors, non-finite values, exact large decimals, and custom conversions.
Validation:
mvn -B -Dtest=MultipleOfValidatorTest teston JDK 8 — 194 tests passed.